home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / sgcapture / src / sgcapture.java
Encoding:
Java Source  |  2000-09-28  |  2.6 KB  |  107 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. import quicktime.qd.*;
  12. import quicktime.*;
  13. import quicktime.util.*;
  14.  
  15.  
  16. import quicktime.io.*;
  17. import quicktime.std.StdQTConstants;
  18. import quicktime.std.sg.*;
  19.  
  20. import quicktime.app.sg.SGDrawer;
  21. import quicktime.std.movies.*;
  22. import quicktime.app.display.QTCanvas;
  23.  
  24. public class SGCapture extends Frame implements WindowListener, StdQTConstants, Errors {    
  25.  
  26.     static final int kWidth = 320;
  27.     static final int kHeight = 240;
  28.     
  29.     public static void main (String args[]) {
  30.     try {
  31.         SGCapture pm = new SGCapture("QT in Java");
  32.         pm.show();
  33.         pm.toFront();
  34.         } catch (Exception e) {
  35.             e.printStackTrace();
  36.             QTSession.close();
  37.         }
  38.     }
  39.  
  40.     SGCapture (String title) {
  41.         super (title);
  42.         try {        
  43.             QTSession.open();        
  44.             myQTCanvas = new QTCanvas(QTCanvas.kPerformanceResize, 0.5F, 0.5F);
  45.             myQTCanvas.setMaximumSize (new Dimension (640, 480));
  46.  
  47.             add ("Center", myQTCanvas);    
  48.             addNotify();
  49.             Insets insets = getInsets();
  50.             setBounds (0, 0, (insets.left + insets.right + kWidth), (insets.top + insets.bottom + kHeight));
  51.         
  52.             addWindowListener(this);
  53.         } catch (Exception ee) {
  54.             ee.printStackTrace();
  55.             QTSession.close();
  56.         }
  57.     }
  58.  
  59.     private QTCanvas         myQTCanvas;
  60.     private SGSoundChannel    mAudio;
  61.     private SGDrawer        mDrawable;
  62.     private QTFile            mFile;
  63.     private Movie            mMovie;
  64.     
  65.     public void windowClosing (WindowEvent e) {
  66.         QTSession.close();
  67.         dispose();
  68.     }
  69.  
  70.     public void windowIconified (WindowEvent e) {
  71.     }
  72.     
  73.     public void windowDeiconified (WindowEvent e) {
  74.     }
  75.     
  76.     public void windowClosed (WindowEvent e) { 
  77.         System.exit(0);
  78.     }
  79.     
  80.     public void windowOpened (WindowEvent e) {
  81.         try{        
  82.             SequenceGrabber mGrabber = new SequenceGrabber();
  83.             
  84.             SGVideoChannel mVideo = new SGVideoChannel(mGrabber);
  85.             
  86.             mVideo.settingsDialog ();
  87.             
  88.             mVideo.setBounds (new QDRect(kWidth, kHeight));
  89.             mVideo.setUsage (seqGrabPreview | seqGrabRecord | seqGrabPlayDuringRecord); // seqGrabRecord
  90.         
  91.             mAudio =  new SGSoundChannel(mGrabber);
  92.             mAudio.setUsage (seqGrabPreview | seqGrabRecord | seqGrabPlayDuringRecord); // seqGrabRecord
  93.             mAudio.setVolume (2);
  94.             
  95.             mDrawable = new SGDrawer(mVideo);            
  96.             myQTCanvas.setClient(mDrawable,true);            
  97.             mGrabber.prepare(true,false);
  98.             mGrabber.startPreview();
  99.         } catch (Exception ee) {
  100.             ee.printStackTrace();
  101.             QTSession.close();
  102.         }
  103.     }
  104.     public void windowActivated (WindowEvent e) {}
  105.     public void windowDeactivated (WindowEvent e) {}
  106. }
  107.